package com.gt.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.app.common.TreatEnum;
import com.gt.app.domain.*;
import com.gt.app.domain.dto.EsTreatInfoDto;
import com.gt.app.mapper.EsTreatInfoMapper;
import com.gt.app.service.EsTreatInfoItemService;
import com.gt.app.service.EsTreatInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 治疗信息表 服务实现类
 * </p>
 *
 * @author caidesheng
 */
@Slf4j
@Service
public class EsTreatInfoServiceImpl extends ServiceImpl<EsTreatInfoMapper, EsTreatInfo> implements EsTreatInfoService {

    @Autowired
    private EsTreatInfoItemService esTreatInfoItemService;

    @Override
    public List<EsTreatInfoDto> getTreatInfoById(String checkId) {
        List<EsTreatInfoDto> treatInfoDtoList = new ArrayList<>();
        LambdaQueryWrapper<EsTreatInfo> eq = new LambdaQueryWrapper<EsTreatInfo>().eq(EsTreatInfo::getEsCheckId, checkId);
        List<EsTreatInfo> esTreatInfos = this.list(eq);
        if (esTreatInfos == null){
            return null;
        }
        for (EsTreatInfo esTreatInfo : esTreatInfos) {
            EsTreatInfoDto esTreatInfoDto = new EsTreatInfoDto();
            BeanUtils.copyProperties(esTreatInfo,esTreatInfoDto);
            LambdaQueryWrapper<EsTreatInfoItem> wapper = new LambdaQueryWrapper<EsTreatInfoItem>().eq(EsTreatInfoItem::getTreatInfoId, esTreatInfo.getOrdrowid());
            List<EsTreatInfoItem> treatInfoItemList = esTreatInfoItemService.list(wapper);

            List<String> prepareMethod = new ArrayList<>();
            List<String> specialObservationMode = new ArrayList<>();
            List<String> mucosaInjection = new ArrayList<>();
            List<String> ministerDrawWay = new ArrayList<>();

            for (EsTreatInfoItem esTreatInfoItem : treatInfoItemList) {
                if (TreatEnum.PREPARE_METHOD.getName().equals(esTreatInfoItem.getType())){
                    prepareMethod.add(esTreatInfoItem.getItem());
                }
                if (TreatEnum.SPECIAL_OBSERVATION_MODE.getName().equals(esTreatInfoItem.getType())){
                    specialObservationMode.add(esTreatInfoItem.getItem());
                }
                if (TreatEnum.MUCOSA_INJECTION.getName().equals(esTreatInfoItem.getType())){
                    mucosaInjection.add(esTreatInfoItem.getItem());
                }
                if (TreatEnum.MINISTER_DRAW_WAY.getName().equals(esTreatInfoItem.getType())){
                    ministerDrawWay.add(esTreatInfoItem.getItem());
                }
            }
            esTreatInfoDto.setPrepareMethod(prepareMethod);
            esTreatInfoDto.setSpecialObservationMode(specialObservationMode);
            esTreatInfoDto.setMucosaInjection(mucosaInjection);
            esTreatInfoDto.setMinisterDrawWay(ministerDrawWay);
            treatInfoDtoList.add(esTreatInfoDto);
        }
        return treatInfoDtoList;
    }
}













